package fr.vahren.dotastrat.game.effect;

import org.json.simple.JSONObject;

import fr.vahren.dotastrat.model.D2SAbility;
import fr.vahren.dotastrat.model.D2SHeroUnit;
import fr.vahren.dotastrat.model.D2SUnit;
import fr.vahren.dotastrat.model.D2SZone;

/**
 * Class for any effect in the game. Effects are something that happens at the
 * end of one or more turns. An effect can target a unit, or a zone (in this
 * case it usually affects all units in this zone).
 * 
 * This class is supposed to be implemented for each hero ability that creates
 * an effect, as an anonymous class in the heroBuilder class.
 * 
 * @author baaleze
 * 
 */
public abstract class D2SEffect implements D2SAttackListner,
		D2SAbilityListener, D2SMoveListener {

	private int remainingTurns;

	private D2SHeroUnit unitTarget;
	private D2SZone zoneTarget;

	/**
	 * Called when the effect is created on the target. Defines the duration. If
	 * the duration is 1 the effect will wear off at the same turn it was
	 * created.
	 */
	public abstract void initEffect(int duration);

	/**
	 * Called each turn the effect is active.
	 */
	public abstract void applyEffect();

	/**
	 * Called the turn the effect wears off.
	 */
	public abstract void finish();

	/**
	 * @return the remainingTurns
	 */
	public int getRemainingTurns() {
		return remainingTurns;
	}

	/**
	 * @param remainingTurns
	 *            the remainingTurns to set
	 */
	public void setRemainingTurns(int remainingTurns) {
		this.remainingTurns = remainingTurns;
	}

	/**
	 * @return the unitTarget
	 */
	public D2SHeroUnit getUnitTarget() {
		return unitTarget;
	}

	/**
	 * @param unitTarget
	 *            the unitTarget to set
	 */
	public void setUnitTarget(D2SHeroUnit unitTarget) {
		this.unitTarget = unitTarget;
	}

	/**
	 * @return the zoneTarget
	 */
	public D2SZone getZoneTarget() {
		return zoneTarget;
	}

	/**
	 * @param zoneTarget
	 *            the zoneTarget to set
	 */
	public void setZoneTarget(D2SZone zoneTarget) {
		this.zoneTarget = zoneTarget;
	}

	public void tick() {
		remainingTurns--;
	}

	public JSONObject generateInfo() {
		// TODO Auto-generated method stub
		return null;
	}

	public static D2SEffect stunEffect(int stunDuration) {
		return new D2SEffect() {

			@Override
			public void initEffect(int duration) {
				// TODO Auto-generated method stub

			}

			@Override
			public void finish() {
				// TODO Auto-generated method stub

			}

			@Override
			public void applyEffect() {
				// TODO Auto-generated method stub

			}

			@Override
			public void onAttack(D2SUnit target, D2SUnit unit) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onMove(D2SHeroUnit d2sHeroUnit, int startZone,
					int targetZone) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onAbilityUsed(D2SHeroUnit d2sHeroUnit,
					D2SAbility ability) {
				// TODO Auto-generated method stub

			}
		};
	}

}
